package ivo.action;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import ivo.pojo.AcarristPO;
import ivo.pojo.AeqptptPO;
import ivo.pojo.AeqptstPO;
import ivo.pojo.DcarrixfPO;
import ivo.pojo.RetBoxPO;
import ivo.pojo.StockerPO;
import ivo.service.impl.CrrService;
import ivo.service.impl.WfmService;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import ivo.util.GetSystemTime;

import com.opensymphony.xwork2.ActionSupport;

@Controller
@Scope("prototype")
public class WfmAction extends ActionSupport {
	private Logger logger = Logger.getLogger(WfmAction.class);

	private WfmService wfmService;
	private CrrService crrService;
	private List<AeqptstPO> aeqptstList;
	private List<AcarristPO> transfterList;
	private List<AeqptptPO> aeqptptList;
	private String sysTimestamp;
	private List<AcarristPO> mainOperCrrCntList;
	private List<RetBoxPO> CrrInfoList;
	private List<AcarristPO> boxIdList;
	private List<AeqptstPO> eqstatktlist;
	private List<AeqptstPO> eqstatOklist;
	private List<AeqptstPO> toolTactTime;
	//private List<AcarristPO> getstkCrrList;
	private String bay_id;
	List<StockerPO> stockerPOList = new ArrayList<StockerPO>();
	

	private String layout;

	public String queryEqStat() {
		HttpServletRequest request = ServletActionContext.getRequest();
		sysTimestamp = GetSystemTime.getEvtTime();
		String ip = request.getRemoteAddr();
//		logger.info("任务开始>selectEqStat........IP:" + ip);
		aeqptstList = wfmService.selectEqStat();
		aeqptptList = wfmService.selectPtStat();
		/*eqstatktlist= wfmService.selectEqStatKT();
		eqstatOklist=wfmService.selectEqStatKT();*/
		/*toolTactTime=wfmService.selectEqStatKT();*/
		return SUCCESS;
	}
	public String queryMainOperCrrCnt(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String jsonStr = request.getParameter("selData");
		JSONObject jsonObj = JSONObject.fromObject(jsonStr);
		String to_eqpt_id = jsonObj.getString("to_eqpt_id");
//		logger.info("任务开始>selectMainOperCrrCnt........to_eqpt_id : " + to_eqpt_id);
		mainOperCrrCntList = wfmService.selectMainOperCrrCnt(to_eqpt_id);
		return SUCCESS;
	}	
//	public String queryStkCrrlist(){
//	HttpServletRequest request = ServletActionContext.getRequest();
//			String jsonStr = request.getParameter("selData");
//			JSONObject jsonObj = JSONObject.fromObject(jsonStr);
//			String stk_id = jsonObj.getString("stkID");
//			logger.info("获取当前STK中的CRR........stkID : " + stk_id);
//			getstkCrrList = wfmService.selectDcarristStkCrrList(stk_id);
//			return SUCCESS;
//	}

	public String queryTransfter() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String jsonStr = request.getParameter("selData");
		JSONObject jsonObj = JSONObject.fromObject(jsonStr);
		String eqptID = jsonObj.getString("eqptID");
//		logger.info("任务开始>selectTransfter........eqptID : " + eqptID);
		transfterList = wfmService.selectTransfter(eqptID);
		return SUCCESS;
	}
//	public String getStkLayout(){
//		HttpServletRequest request = ServletActionContext.getRequest();
//		String jsonStr = request.getParameter("selData");
//		JSONObject jsonObj = JSONObject.fromObject(jsonStr);
//		String stk_id = jsonObj.getString("stk_id");
//		logger.info("本次请求的STK_id 为 : " + stk_id);
//		layout = wfmService.getStkLayout(stk_id);
//		return SUCCESS;
//	}
	public String queryCrrInfo(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String jsonStr = request.getParameter("selData");
		JSONObject jsonObj = JSONObject.fromObject(jsonStr);
		String crrID = jsonObj.getString("crrID");
//		logger.info("任务开始>selectCrrInfo........crrID : " + crrID);
		CrrInfoList = wfmService.selectCrrInfo(crrID);
		return SUCCESS;
	}

	public String queryBoxIdInfo(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String jsonStr = request.getParameter("selData");
		JSONObject jsonObj = JSONObject.fromObject(jsonStr);
		String shelfID=jsonObj.getString("xfrshelfID");
		boxIdList=wfmService.selectBoxId(shelfID);
		return SUCCESS;
		
	}
	public String queryEqptBay(){
		stockerPOList = crrService.isBusy();
		return SUCCESS;
	}
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Resource
	public void setWfmService(WfmService wfmService) {
		this.wfmService = wfmService;
	}

	@Resource
	public void setCrrService(CrrService crrService) {
		this.crrService = crrService;
	}

	public List<AeqptstPO> getAeqptstList() {
		return aeqptstList;
	}

	public void setAeqptstList(List<AeqptstPO> aeqptstList) {
		this.aeqptstList = aeqptstList;
	}

	public List<AeqptstPO> getEqstatOklist() {
		return eqstatOklist;
	}
	public void setEqstatOklist(List<AeqptstPO> eqstatOklist) {
		this.eqstatOklist = eqstatOklist;
	}
	public List<AcarristPO> getTransfterList() {
		return transfterList;
	}

	public void setTransfterList(List<AcarristPO> transfterList) {
		this.transfterList = transfterList;
	}

	public List<AeqptptPO> getAeqptptList() {
		return aeqptptList;
	}

	public void setAeqptptList(List<AeqptptPO> aeqptptList) {
		this.aeqptptList = aeqptptList;
	}

	public String getSysTimestamp() {
		return sysTimestamp;
	}

	public List<AeqptstPO> getToolTactTime() {
		return toolTactTime;
	}
	public void setToolTactTime(List<AeqptstPO> toolTactTime) {
		this.toolTactTime = toolTactTime;
	}
	public List<AcarristPO> getMainOperCrrCntList() {
		return mainOperCrrCntList;
	}

	public void setMainOperCrrCntList(List<AcarristPO> mainOperCrrCntList) {
		this.mainOperCrrCntList = mainOperCrrCntList;
	}

	public String getLayout() {
		return layout;
	}

	public void setLayout(String layout) {
		this.layout = layout;
	}

	public List<RetBoxPO> getCrrInfoList() {
		return CrrInfoList;
	}

	public void setCrrInfoList(List<RetBoxPO> crrInfoList) {
		this.CrrInfoList = crrInfoList;
	}

	public String getBay_id() {
		return bay_id;
	}

	public void setBay_id(String bay_id) {
		this.bay_id = bay_id;
	}

	public List<StockerPO> getStockerPOList() {
		return stockerPOList;
	}
//	public List<AcarristPO> getGetstkCrrList() {
//		return getstkCrrList;
//	}
//
//	public void setGetstkCrrList(List<AcarristPO> getstkCrrList) {
//		this.getstkCrrList = getstkCrrList;
//	}

	public List<AeqptstPO> getEqstatktlist() {
		return eqstatktlist;
	}

	public List<AcarristPO> getBoxIdList() {
		return boxIdList;
	}
	public void setBoxIdList(List<AcarristPO> boxIdList) {
		this.boxIdList = boxIdList;
	}
	public void setEqstatktlist(List<AeqptstPO> eqstatktlist) {
		this.eqstatktlist = eqstatktlist;
	}

	

	
}
